package offer.system;

import java.util.ArrayList;

import system.bean.Operation;
import system.dao.OperationDao;

public class OperationSource {

	private static OperationDao operationDao = new OperationDao();
	
	public static boolean addOperation(Operation bean){
		boolean successed = false;
		if(!operationDao.isExist(bean)){
			successed = operationDao.insert(bean);
		}
		return successed;
	}
	
	public static  ArrayList<Object> getList(){
		 String sql       =  "select * from " + Operation.tableName;
		 String exception =  "OperationSource :function getList()";
		 ArrayList<Object> list = operationDao.getList(sql, exception);
		 return list;
	}
	
	public static boolean SaveOperation(Operation bean){
		boolean success = false;
		
		if(operationDao.isExist(bean)){
			if(operationDao.checkRepeatForInsert(bean)){
				return false;
			}
			success = operationDao.update(bean);
		}else{
			if(operationDao.checkRepeatForUpdate(bean)){
				return false;
			}
			success = operationDao.insert(bean);
		}
		
		return success;
	}
	
	public static Operation getOpeartionById(int operationId){
		return operationDao.getBeanById(operationId);
	}
	
	public static Operation getOpeartionByIdentify(String identify){
		return operationDao.getBeanByIdentify(identify);
	}
	
	public static boolean DeleteOperationById(int operationId){
		Operation operation = new Operation();
		operation.setOperationId(operationId);
		return operationDao.delete(operation);
	}
}
